package properties;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : PropertiesDemo1
 * @Author : 54061
 * @Date: 2022/2/15 15:57
 */
public class PropertiesDemo1 {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        //增
        properties.setProperty("version", "1.0");
        properties.setProperty("author", "Damon");
        properties.setProperty("Date", "2021/12/25");

        //一键存储
        //void store(OutputStream out, String comments)
        //void store(Writer writer, String comments)
        FileOutputStream fos = new FileOutputStream("T_Day21\\aaa\\info.properties");

        properties.store(fos, "Damon  谈斌");

        fos.close();

        System.out.println("------------------------------");
        Properties properties1 = new Properties();

        //一键加载文件中的属性集到集合中
        // void load(InputStream inStream)
        // void load(Reader reader)
        FileInputStream fis = new FileInputStream("T_Day21\\aaa\\info.properties");
        properties1.load(fis);
        Set<String> keys = properties1.stringPropertyNames();
        for (String key : keys) {
            String value = properties1.getProperty(key);
            System.out.println(key + " --- " + value);
        }
    }
}